/**
 * Created by ray on 17/1/11.
 */
import CryptoJS from 'crypto-js'

var key = CryptoJS.enc.Utf8.parse('sklhd***jfsdgdeg');
var iv = CryptoJS.enc.Utf8.parse('cf**dfgsdf_ccvd1');

// var aesEncrypt = "8MQxSVbG9qsHGt9sRLuCAbmgA5xT+P5YjK9DHWYMSdg=";
// var aesDecrypt = "张三 李四 王五00";
//wp75F+xK0yPvGtU+b3RSpmlsGHxzm9mT0AD4gHchEVWL8aPDBggKOHVIfQCJKKrzgPB//SWjpBlWIighAwlBBqd91ns8g1Oj55hXVC816BKc81njmjH20LI0XhjZoBYgJUlBZnn+eVVXaGIurFCrUicW58eCjZyvzEaRjcqrsaI=
//"wp75F+xK0yPvGtU+b3RSpvHtGZgNyHv6O9wIkjFTReGntOWFItwg2pvbOPSTmgapvVLG9HF0nSN1aNMeZf9gkoaZ7mCD2ctxudsu5KA6qWttA4/QUVsbISEWo1jr5CIrjLrgj3J33SNaJAnz1QtieeNGOCj/XpGlYvOW9JBljw8="


module.exports = {
  b64Encode: function (str) {
    return btoa(encodeURIComponent(str));
  },
  b64Decode: function (str) {
    return decodeURIComponent(atob(str));
  },
  test: function () {
    var aes = this;//require("./aes.js");
    var aaa = aes.aesEncrypt('张三 李四 王五00')
    console.log("aesEncrypt: " + aaa);
    var bbb = aes.aesDecrypt(aaa)
    console.log("aesDecrypt: " + bbb);
  },
  //加密
  aesEncrypt: function (word) {
    var srcs = CryptoJS.enc.Utf8.parse(word);
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {
      iv: iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.ZeroPadding
    });
    return encrypted.toString();
  },
  //解密
  aesDecrypt: function (word) {
    // word = word.replace(/\r\n/ig,"<br/>");
    // console.log("aesDecrypt: " );
    // var srcs = CryptoJS.enc.Utf8.parse(word);
    var decrypt = CryptoJS.AES.decrypt(word, key, {iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding});
    return CryptoJS.enc.Utf8.stringify(decrypt).toString();
  }
}
  
